package cn.sh.basic.listener;


import cn.sh.basic.service.IPermissionScanService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener//申明自定义的web监听器，被容器注册和使用
public class PermissionScanInitListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("项目启动前要执行这里的代码");
        //这里就要开启异步线程来执行我们的业务代码
        new Thread(new Runnable() {
            @Override
            public void run() {
                permissionScanService.scanPermission();
            }
        }).start();
    }
}